<template>
	<view class="x-wrapper">
		<view class="x-main-content">
			<view class="hosp-box">
				<u-navbar title="热门医院" :fixed="true" leftIcon="arrow-left" leftIconColor="#000" leftIconSize="42rpx"
					autoBack placeholder>
				</u-navbar>
				<view style="position: fixed;width: 100%;z-index: 9;height: 50rpx;right: 0;">
					<search @toSearch="toSearch"></search>
				</view>
				<view class="list-box">
					<template v-if="hospitalList&&hospitalList.length">
						<hosp-item v-for="(item, index) in hospitalList" :key="item.id" :item="item"></hosp-item>
					</template>
					<view class="x-no-data" v-if="hospitalList.length===0">
						<u-empty text="暂无数据" mode="data" marginTop="100"></u-empty>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import search from '@/components/search.vue'
	import hospItem from '@/components/hosp/index'
	import hospitalCard from "../../pages/business/components/hospitalCard.vue"
	export default {
		components: {
			hospitalCard,
			hospItem,
			search
		},
		data() {
			return {
				params: {
					cityCode: '',
					pageNum: 1,
					pageSize: 10,
					keyword:'',
				},
				hospitalList: [],
				listTotal: '',
			}
		},
		onShow() {
			// uni.showLoading({
			// 	title: '加载中',
			// 	mask: true
			// })
			this.getHospitalData()
		},
		computed: {
			totalPage() {
				return Math.ceil(this.listTotal / this.params.pageSize)
			}
		},
		onReachBottom() {
			this.params.pageNum++
			if (this.params.pageNum > this.totalPage) {
				return
			} else {
				this.getHospitalData()
			}
		},
		methods: {
			toSearch(ctx){
				this.keyword = ctx
				this.getHospitalData()
			},
			async getHospitalData() {
				this.params.cityCode = uni.getStorageSync('myAddress').cityId
				console.log(uni.getStorageSync('myAddress'))
				let res = await this.$request('/api/index/getAllHospitalList', this.params, 'GET')
				console.log(res)
				if (res.data.rows.length) {
					for (let i = 0; i < res.data.rows.length; i++) {
						this.hospitalList.push(res.data.rows[i])
					}
					this.listTotal = res.data.total
					// uni.hideLoading()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hosp-box {
		.top-box {
			padding: 20rpx 40rpx 30rpx;
			background: #fff;

			.search-box {
				height: 64rpx;
				background: #F8FAFF;
				border-radius: 64rpx;
				display: flex;
				align-items: center;
				// margin-bottom: 24rpx;

				.s-btn {
					margin-right: 5rpx;
					width: 118rpx;
					height: 54rpx;

					/deep/ .u-button__text {
						font-size: 24rpx !important;
					}
				}
			}
		}
	}

	.list-box {
		padding: 0 40rpx 1rpx;
		margin-top: 120rpx;

		.hosp-item {
			&:last-child {
				margin-bottom: 0;
			}
		}
	}
</style>